package com.ruoyi.business.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import com.ruoyi.business.service.IBusHardwareCheckTimeCommonUpdateService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.BusHardwareCheckTimeUpdateMapper;
import com.ruoyi.business.domain.BusHardwareCheckTimeUpdate;
import com.ruoyi.business.service.IBusHardwareCheckTimeUpdateService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 硬件检定日期更新Service业务层处理
 * 
 * @author asher
 * @date 2021-10-24
 */
@Service
public class BusHardwareCheckTimeUpdateServiceImpl implements IBusHardwareCheckTimeUpdateService
{
    @Autowired
    private BusHardwareCheckTimeUpdateMapper busHardwareCheckTimeUpdateMapper;

    @Autowired
    @Qualifier("busSensorServiceImpl")
    private BusSensorServiceImpl busSensorService;

    @Autowired
    @Qualifier("busAcquisitionCardServiceImpl")
    private BusAcquisitionCardServiceImpl busAcquisitionCardService;

    @Autowired
    @Qualifier("busDeviceServiceImpl")
    private BusDeviceServiceImpl busDeviceService;

    /**
     * 查询硬件检定日期更新
     * 
     * @param recordId 硬件检定日期更新主键
     * @return 硬件检定日期更新
     */
    @Override
    public BusHardwareCheckTimeUpdate selectBusHardwareCheckTimeUpdateByRecordId(Long recordId)
    {
        return busHardwareCheckTimeUpdateMapper.selectBusHardwareCheckTimeUpdateByRecordId(recordId);
    }

    /**
     * 查询硬件检定日期更新列表
     * 
     * @param busHardwareCheckTimeUpdate 硬件检定日期更新
     * @return 硬件检定日期更新
     */
    @Override
    public List<BusHardwareCheckTimeUpdate> selectBusHardwareCheckTimeUpdateList(BusHardwareCheckTimeUpdate busHardwareCheckTimeUpdate)
    {
        return busHardwareCheckTimeUpdateMapper.selectBusHardwareCheckTimeUpdateList(busHardwareCheckTimeUpdate);
    }

    /**
     * 新增硬件检定日期更新
     * 
     * @param busHardwareCheckTimeUpdate 硬件检定日期更新
     * @return 结果
     */
    @Override
    public int insertBusHardwareCheckTimeUpdate(BusHardwareCheckTimeUpdate busHardwareCheckTimeUpdate)
    {
        busHardwareCheckTimeUpdate.setCreateTime(DateUtils.getNowDate());
        return busHardwareCheckTimeUpdateMapper.insertBusHardwareCheckTimeUpdate(busHardwareCheckTimeUpdate);
    }

    /**
     * 修改硬件检定日期更新
     * 
     * @param busHardwareCheckTimeUpdate 硬件检定日期更新
     * @return 结果
     */
    @Override
    public int updateBusHardwareCheckTimeUpdate(BusHardwareCheckTimeUpdate busHardwareCheckTimeUpdate)
    {
        busHardwareCheckTimeUpdate.setUpdateTime(DateUtils.getNowDate());
        return busHardwareCheckTimeUpdateMapper.updateBusHardwareCheckTimeUpdate(busHardwareCheckTimeUpdate);
    }

    /**
     * 批量删除硬件检定日期更新
     * 
     * @param recordIds 需要删除的硬件检定日期更新主键
     * @return 结果
     */
    @Override
    public int deleteBusHardwareCheckTimeUpdateByRecordIds(Long[] recordIds)
    {
        return busHardwareCheckTimeUpdateMapper.deleteBusHardwareCheckTimeUpdateByRecordIds(recordIds);
    }

    /**
     * 删除硬件检定日期更新信息
     * 
     * @param recordId 硬件检定日期更新主键
     * @return 结果
     */
    @Override
    public int deleteBusHardwareCheckTimeUpdateByRecordId(Long recordId)
    {
        return busHardwareCheckTimeUpdateMapper.deleteBusHardwareCheckTimeUpdateByRecordId(recordId);
    }

    @Transactional
    @Override
    public int updateCheckTimeByDestRecordId(BusHardwareCheckTimeUpdate busHardwareCheckTimeUpdate) {
        HashMap<String, IBusHardwareCheckTimeCommonUpdateService> updateTypeMap = new HashMap<String, IBusHardwareCheckTimeCommonUpdateService>(){
            {
                put("DEVICE", busDeviceService);
            }
        };

        HashMap<String, String> destTableMap = new HashMap<String, String>(){
            {
                put("DEVICE", "bus_device");
            }
        };
        String updateType = busHardwareCheckTimeUpdate.getUpdateType();
        IBusHardwareCheckTimeCommonUpdateService iBusHardwareCheckTimeCommonUpdateService = updateTypeMap.get(updateType);
        int updateResult = iBusHardwareCheckTimeCommonUpdateService.updateCheckTimeByDestRecordId(busHardwareCheckTimeUpdate.getDestRecordId(), busHardwareCheckTimeUpdate.getCheckTime(), busHardwareCheckTimeUpdate.getCheckCompany());
        busHardwareCheckTimeUpdate.setDestTable(destTableMap.get(updateType));
        int insertResult = this.insertBusHardwareCheckTimeUpdate(busHardwareCheckTimeUpdate);
        return updateResult & insertResult;
    }

}
